import { DynamicModule, Global, Module } from '@nestjs/common';
import { UploaderService } from './uploader.service';
import { UploaderConfig } from './type/config';

@Global()
export class UploaderModule {
	static forRootAsync(options: {
		imports?: any[];
		useFactory: (...args: any[]) => Promise<UploaderConfig> | UploaderConfig;
		inject?: any[];
		}): DynamicModule {
		const providers = [
			{
			provide: 'UPLOADER_CONFIG',
			useFactory: options.useFactory,
			inject: options.inject || [],
			},
			UploaderService,
		];
	
		return {
			module: UploaderModule,
			providers: providers,
			exports: [UploaderService],
		};
	}
}
